package com.freshcity.utils
{
	import com.freshcity.core.GlobalVar;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.net.registerClassAlias;
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;

	public class GlobalUtil
	{
		public static function clone(object:Object):Object
		{
			var qClassName:String=getQualifiedClassName(object);
			var objectType:Class=getDefinitionByName(qClassName) as Class;
			registerClassAlias(qClassName, objectType);
			var copier:ByteArray=new ByteArray();
			copier.writeObject(object);
			copier.position=0;
			return copier.readObject();
		}
		
		public static function dictLen(myDict:Dictionary):int 
		{
			var n:int = 0;
			for (var key:* in myDict) {
				n++;
			}
			return n;
		}
		
		public static function regPoint($obj:Sprite , $point:Point):void
		{
			var tmp_point:Point = $obj.parent.globalToLocal($obj.localToGlobal($point));
			var len:int = $obj.numChildren;
			while (len>0)
			{
				len--;
				var tmp_obj:DisplayObject = $obj.getChildAt(len);
				tmp_obj.x -=  $point.x;
				tmp_obj.y -=  $point.y;
			}
			$obj.x = tmp_point.x;
			$obj.y = tmp_point.y;
		}		
		
		public static function isEmpty(obj:*):Boolean {
			if (obj == undefined)
				return true;
			
			if (obj is Number)
				return isNaN(obj);
			
			if (obj is Array || obj is String)
				return obj.length == 0;
			
			if (obj is Object) {
				for (var prop:String in obj)
					return false;
				
				return true;
			}
			return false;
		}
		
		public static function guideIsDone(posIndex:int):Boolean
		{
			var step:String = GlobalVar.LOGIN_USER.guideStep;
			var loc1:String = step.substring(posIndex,posIndex+1);
			return loc1 == "1";
		}
	}
}
